﻿using System;
using System.Web.UI.WebControls;
using Portal.Data.Helper;
using App_Code.Modules;
using Portal.Core;
using Portal.Core.Binding;
using Portal.Data.Entity;

public partial class Modules_Banner_New : BannerModule
{
    protected override string Action
    {
        get { return "newest"; }
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!IsPostBack)
        {
            Positions.DataSource = ObjectBannerPositionClass.ListAll();
            Positions.DataBind();
        }
    }
    private Banner _banner;
    protected Banner NewBanner
    {
        get
        {
            if (_banner == null)
            {
                object obj = Binder.GetData(typeof(Banner), phContent, new BindContext());
                if (obj != null)
                {
                    _banner = (Banner)obj;
                }
            }
            return _banner;
        }
    }
    protected override void Save_Click(object sender, EventArgs e)
    {
        NewBanner.IsText = !string.IsNullOrEmpty(NewBanner.DisplayText) && string.IsNullOrEmpty(NewBanner.Path);
        NewBanner.Save();

        foreach (ListItem item in Positions.Items)
        {
            if (item.Selected)
            {
                var bg = new BannerGroup { BannerID = NewBanner.ID, GroupID = Convert.ToInt32(item.Value) };
                bg.SaveWithoutPermission();
            }
        }

        Forward("Save");
    }
}
